package com.vgooo.client.tool.tester;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;

import com.umeng.analytics.MobclickAgent;
import com.vgooo.client.ViewLayout;


public class BaseTestActivity extends Activity {
	
	private final static String className = "BaseTestActivity" ;
	
	public Bundle mBundle; 
	public ArrayList<String> mValues;
	@SuppressWarnings("unchecked")
	public void init( String item ) {
		Intent intent = this.getIntent();
		Bundle bundle = intent.getExtras();
		
		boolean isdel = false;
		ArrayList values = bundle.getStringArrayList("values");
		for (int i=0;i<values.size();i++) {
			if (((String)values.get(i)).equals( item )) {
				values.remove( i );
				isdel = true;
			}
		}
		if (!isdel) {

			Intent intent2 = new Intent(this , TestRunActivity.class);
			mBundle = new Bundle();
			mBundle.putStringArrayList("values", values);
			intent2.putExtras(mBundle);
			startActivity(intent2);
			finish();
		}
		mValues = values;
		bundle.putStringArrayList("values", values);
		mBundle = bundle;
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		// 友盟统计功能，打开页面
		MobclickAgent.onResume(this);
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		// 友盟统计功能，页面关闭
		MobclickAgent.onPause(this);
		super.onPause();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			//Toast.makeText(this, "bbbbbbbb", Toast.LENGTH_SHORT).show();
//			DebugTools.log(className, mValues.toString());
			if(mValues.isEmpty()){
//				DebugTools.log(className, "showCurrentView()");
//				ViewLayout.showCurrentView();
			}else{
				Intent intent2 = new Intent(this , TestRunActivity.class);
				
				mBundle = new Bundle();
				mBundle.putStringArrayList("values", mValues);
				intent2.putExtras(mBundle);
				startActivity(intent2);
			}
			finish();
			
			return false;
		}
		return super.onKeyDown(keyCode, event);
	}
	
	final static float DEBUG_WIDTH = 480;
	final static float DEBUG_HEIGHT = 800;

	public float getDensity() {
		DisplayMetrics dm = new DisplayMetrics();
		dm = this.getApplicationContext().getResources().getDisplayMetrics();
		float screenWidth = dm.widthPixels;
		float screenHeight = dm.heightPixels;
		float density = dm.density;

		return density;
	}

	public float getDensityWidth() {
		DisplayMetrics dm = new DisplayMetrics();
		dm = this.getApplicationContext().getResources().getDisplayMetrics();
		float screenWidth = dm.widthPixels;

		float density = screenWidth / DEBUG_WIDTH;
		return density;
	}

	public float getDensityHeight() {
		DisplayMetrics dm = new DisplayMetrics();
		dm = this.getApplicationContext().getResources().getDisplayMetrics();
		float screenWidth = dm.widthPixels;

		float density = screenWidth / DEBUG_HEIGHT;
		return density;
	}
	
	
}
